<?php
require_once(dirname(__FILE__) . '/../lib/ProductCustomFilter.class.php');

class productFilterComponents extends myComponents{

    public function executeRender(){
	$this->form = new ProductCustomFilter();
	$this->node = $this->getRoute()->getObject();
	$this->pager = $this->getPager();

    }

    protected function buildQuery(){
	if($this->hasRequestParameter($this->form->getName())){
	    $this->form->bind($this->getRequestParameter($this->form->getName()));	    
	    if($this->form->isValid()){
		$this->setFilters($this->form->getValues());
	    }
	}

	return $this->form->buildQuery($this->getFilters());
    }

    protected function getPager()
    {
	$pager = new sfDoctrinePager( 'Product', 9 );
	$pager->setQuery($this->buildQuery());
	$pager->setPage($this->getRequestParameter('page', 1));
	$pager->init();

	return $pager;
    }

    protected function getFilters(){
	return $this->getUser()->getAttribute('product.filters', array());
    }

    protected function setFilters(array $filters){
	return $this->getUser()->setAttribute('product.filters', $filters);
    }
}